﻿#region Librerias

using System.Windows.Forms;
using ESF.FileHelper.Controls;
using System;
using System.Deployment.Application;
using ESF.WinForms;
using ESF.General;
using ESF.WinForms.Elements;

#endregion


namespace ESF.FileHelper
{
	public partial class Main : BaseForm
	{
		#region Miembros

		private uscFileSizeOptimizer uscFileOptimizer;

		private uscFolderGenerateIndex uscFolderGenerateIndex;

		private uscRenameFiles uscRenameFiles;

		private uscMergePDFs uscMergePDFs;

		private uscCopyDirectories uscCopyDirectories;

		#endregion


		#region Constructor
		
		public Main() : base ()
		{
			InitializeComponent();

			uscFileOptimizer = new uscFileSizeOptimizer ();
			uscFileOptimizer.ReturningMenu += ReturnView;

			uscFolderGenerateIndex = new uscFolderGenerateIndex ();
			uscFolderGenerateIndex.ReturningMenu += ReturnView;

			uscRenameFiles = new uscRenameFiles ();
			uscRenameFiles.ReturningMenu += ReturnView;

			uscMergePDFs = new uscMergePDFs ();
			uscMergePDFs.ReturningMenu += ReturnView;

			uscCopyDirectories = new uscCopyDirectories ();
			uscCopyDirectories.ReturningMenu += ReturnView;

			lblProductVersion.Text = string.Format ("Versión {0}", ReadConfig.ExecutingVersion);
		}

		#endregion
		

		#region Funciones

		private void ReturnView ()
		{
			tbp_1.Visible = true;

			pnlControlContainer.Visible = false;

			Height = 504;

			WinFormsHelper.ShowAtCenter (this);
		}


		private void ShowControl (Control pControl)
		{
			tbp_1.Visible = false;

			pnlControlContainer.Visible = true;

			if (pnlControlContainer.Controls.Count > 0)
			{			
				pnlControlContainer.Controls.RemoveAt (0);
			}

			pControl.Dock = DockStyle.Top; 
			
			pnlControlContainer.Controls.Add(pControl);
			
			Height = pControl.Height + 30;

			WinFormsHelper.ShowAtCenter(this);
		}


		private void ShowGenerateIndex ()
		{
			ShowControl (uscFolderGenerateIndex);
		}


		private void ShowRenameFiles ()
		{
			ShowControl (uscRenameFiles);
		}


		private void ShowFormalizeFiles()
		{
			ShowControl (uscFileOptimizer);
		}

		
		private void ShowMergePDFs()
		{
			ShowControl (uscMergePDFs);
		}


		private void ShowCopyDirectories()
		{
			ShowControl (uscCopyDirectories);
		}

		#endregion


		#region Window Events
		
		private void Main_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (WinFormsHelper.ShowConfirm (this, "Esta seguro que desea cerrar la aplicación?"))
			{
				CloseApplication ();
				return;
			}

			e.Cancel = true;
		}

		#endregion


		#region Generate Index Events

		private void imgIcoGenerateIndex_MouseClick(object sender, MouseEventArgs e)
		{
			ShowGenerateIndex ();
		}
		
		private void lblTitGenerateIndex_MouseClick(object sender, MouseEventArgs e)
		{
			ShowGenerateIndex ();
		}

		private void lblDesGenerateIndex_MouseClick(object sender, MouseEventArgs e)
		{
			ShowGenerateIndex ();
		}

		#endregion


		#region RenameFoldeFiles Events

		private void lblDesRenameFolderFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowRenameFiles ();
		}

		private void lblTitRenameFolderFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowRenameFiles();
		}

		private void imgIcoRenameFolderFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowRenameFiles();
		}

		#endregion


		#region FormalizeFiles Events

		private void lblDesFormalizeFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowFormalizeFiles ();
		}

		private void lblTitFormatizeFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowFormalizeFiles();
		}

		private void imgIcoFormatizeFiles_MouseClick(object sender, MouseEventArgs e)
		{
			ShowFormalizeFiles();
		}
		
		#endregion


		#region MergePDFs Events

		private void lblDesMergePDFs_MouseClick(object sender, MouseEventArgs e)
		{
			ShowMergePDFs ();
		}			

		private void lblTitMergePDFs_MouseClick(object sender, MouseEventArgs e)
		{
			ShowMergePDFs();
		}

		private void imgIcoMergePDFs_MouseClick(object sender, MouseEventArgs e)
		{
			ShowMergePDFs();
		}

		#endregion

		
		#region Copy Directories Events
		
		private void imgIcoCopyDirectories_MouseClick(object sender, MouseEventArgs e)
		{
			ShowCopyDirectories ();
		}

		private void lblDesCopyDirectories_MouseClick(object sender, MouseEventArgs e)
		{
			ShowCopyDirectories();
		}

		private void lblTitleCopyDirectories_MouseClick(object sender, MouseEventArgs e)
		{
			ShowCopyDirectories();
		}

		#endregion		
	}
}
